package com.ruoyi.web.controller.emergencyplan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.emergencyplan.domain.EpEmergencyPlan;
import com.ruoyi.emergencyplan.service.IEpEmergencyPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急预案——应急预案Controller
 * 
 * @author hcc
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/emergencyplan/plan")
public class EpEmergencyPlanController extends BaseController
{
    @Autowired
    private IEpEmergencyPlanService epEmergencyPlanService;

    /**
     * 查询应急预案——应急预案列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpEmergencyPlan epEmergencyPlan)
    {
        startPage();
        List<EpEmergencyPlan> list = epEmergencyPlanService.selectEpEmergencyPlanList(epEmergencyPlan);
        return getDataTable(list);
    }

    /**
     * 导出应急预案——应急预案列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:export')")
    @Log(title = "应急预案——应急预案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpEmergencyPlan epEmergencyPlan)
    {
        List<EpEmergencyPlan> list = epEmergencyPlanService.selectEpEmergencyPlanList(epEmergencyPlan);
        ExcelUtil<EpEmergencyPlan> util = new ExcelUtil<EpEmergencyPlan>(EpEmergencyPlan.class);
        util.exportExcel(response, list, "应急预案——应急预案数据");
    }

    /**
     * 获取应急预案——应急预案详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") String planId)
    {
        return success(epEmergencyPlanService.selectEpEmergencyPlanByPlanId(planId));
    }

    /**
     * 新增应急预案——应急预案
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:add')")
    @Log(title = "应急预案——应急预案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpEmergencyPlan epEmergencyPlan)
    {
        epEmergencyPlan.setPlanId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(epEmergencyPlanService.insertEpEmergencyPlan(epEmergencyPlan));
    }

    /**
     * 修改应急预案——应急预案
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:edit')")
    @Log(title = "应急预案——应急预案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpEmergencyPlan epEmergencyPlan)
    {
        return toAjax(epEmergencyPlanService.updateEpEmergencyPlan(epEmergencyPlan));
    }

    /**
     * 删除应急预案——应急预案
     */
    @PreAuthorize("@ss.hasPermi('emergencyplan:plan:remove')")
    @Log(title = "应急预案——应急预案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable String[] planIds)
    {
        return toAjax(epEmergencyPlanService.deleteEpEmergencyPlanByPlanIds(planIds));
    }
}
